package com.itheima.bos.web.action.take_delivery;

import java.util.HashMap;
import java.util.Map;


import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.bos.domain.take_delivery.Order;
import com.itheima.bos.service.take_delivery.OrderService;
import com.itheima.bos.web.common.action.BaseAction;
import com.opensymphony.xwork2.ActionContext;

@ParentPackage(value="json-default")
@Scope("prototype")
@Namespace("/")
@Controller
public class OrderAction extends BaseAction<Order> {
	
	@Autowired	
	private OrderService orderService;
	
	@Action(value="order_findByOrderNum",results={
			@Result(name="success",type="json")})
	public String findByOrderNum(){
		
		Order order =orderService.findByOrderNum(model.getOrderNum());
		Map<String,Object> map = new HashMap<String,Object>();
		if (order==null) {
			map.put("success", false);
		} else {
			map.put("success", true);
			map.put("orderData", order);
		}
		ActionContext.getContext().getValueStack().push(map);
		return SUCCESS;
	}
	
}
